package com.xiaohei.crm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xiaohei.crm.common.result.Result;
import com.xiaohei.crm.dao.Region;
import com.xiaohei.crm.dao.Role;
import com.xiaohei.crm.service.RegionService;
import com.xiaohei.crm.service.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: RoleController
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/6/22 14:30
 * Version 1.0
 */
@RestController
@RequiredArgsConstructor
@CrossOrigin
public class RoleController {

    private final RoleService roleService;
    /**
     * 分页查询角色信息
     * @return
     */
    @GetMapping("/role/findByPage")
    public Result<IPage> findByPage(){
        return roleService.findByPage();
    }

    /**
     * 添加角色
     * @param
     * @return
     */
    @PostMapping("/role")
    public Result save(@RequestBody Role role){
        roleService.saveRole(role);
        return Result.ok();
    }

    /**
     * 修改角色信息
     * @param
     * @return
     */
    @PutMapping("/role")
    public Result update(@RequestBody Role role){
        roleService.updateByRoleId(role);
        return Result.ok();
    }

    /**
     * 逻辑删除区域
     * @param
     * @return
     */
    @DeleteMapping("role/{id}")
    public Result<String> deleteByUsername(@PathVariable("id") String id){
        roleService.deleteById(id);
        return Result.ok();
    }

}
